<?php
/**
 * <https://y.st./>
 * Copyright © 2018 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Using R',
	'<{subtitle}>' => 'Written in <span title="Introduction to Statistics">MATH 1280</span> by <a href="https://y.st./">Alexand(er|ra) Yst</a>, finalised on 2018-09-19',
	'<{copyright year}>' => '2018',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<p>
	The headings here break the assignment submission up a bit oddly, but each major section answers one of the questions posed by the assignment, in order.
	If you&apos;re grading this, it should be intuitive.
	If you&apos;re reading this from my archive after its release in 2023, that&apos;s why the organisation seems a bit odd.
</p>
<h2>Definitions</h2>
<h3>Sepal</h3>
<p>
	The sepal is the leaf-like, green extensions under the flower (Wikipedia, 2018).
	They tend to be a bit thicker and smaller than leaves, and help support the flower.
</p>
<h3>Petal</h3>
<p>
	Petals are a sort of modified leaf (Wikipedia, 2018).
	They&apos;re usually brightly coloured, and quite a bit softer and more delicate than regular leaves.
	Unlike regular leaves, their purpose isn&apos;t photosynthesis, but instead drawing attention to the flower, which is the plant&apos;s reproductive organ.
	Various pollinators notice the flowers and aid in the plant&apos;s reproductive cycle.
</p>
<h2>Multiple choice</h2>
<p>
	The next part of the assignment asks us what the meaning of the cumulative relative frequency is.
	It&apos;s a running total of the relative frequencies encountered thus far, and for the final value, it&apos;ll always finally add up to one.
	With that in mind, for the example given, the cumulative relative frequency listed for <code>3</code> would be the fraction of petal lengths that are three or less units long, after rounding: <strong>answer D</strong>.
</p>
<h2>Trick question</h2>
<p>
	The assignment asks which petal length occurs most frequently.
	This is a trick question; both petals lengths of four units and five units are tied, at 23% occurrence.
</p>
<h2>Explanation</h2>
<p>
	We were asked to use the cumulative relative frequency table to determine which petal length had the highest occurrence rate.
	To do this, we needed to work backwards and use the cumulative relative frequency to determine the actual relative frequency.
	Accomplishing this is as simple as subtracting the current cumulative relative frequency from the previous cumulative relative frequency.
	If we remember what cumulative relative frequency actually is, we see that before the first entry, there&apos;s always a cumulative relative frequency of zero that isn&apos;t displayed in the table, which we can use when determining the actual relative frequency of the initial displayed item.
	We arrive at the following data:
</p>
<table>
	<tr>
		<th>
			Value:
		</th>
		<th>
			1
		</th>
		<th>
			2
		</th>
		<th>
			3
		</th>
		<th>
			4
		</th>
		<th>
			5
		</th>
		<th>
			6
		</th>
		<th>
			7
		</th>
	</tr>
	<tr>
		<td>
			Relative frequency:
		</td>
		<td>
			0.16
		</td>
		<td>
			0.17
		</td>
		<td>
			0.02
		</td>
		<td>
			0.23
		</td>
		<td>
			0.23
		</td>
		<td>
			0.16
		</td>
		<td>
			0.03
		</td>
	</tr>
</table>
<p>
	Once we have those numbers, it&apos;s simply a matter of comparing them and finding the biggest one (or in this case, the two tied for biggest).
</p>
<h2>Names</h2>
<p>
	Finding the table column names is easy.
</p>
<blockquote>
<pre><code>R version 3.3.3 (2017-03-06) -- &quot;Another Canoe&quot;
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type &apos;license()&apos; or &apos;licence()&apos; for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type &apos;contributors()&apos; for more information and
&apos;citation()&apos; on how to cite R or R packages in publications.

Type &apos;demo()&apos; for some demos, &apos;help()&apos; for on-line help, or
&apos;help.start()&apos; for an HTML browser interface to help.
Type &apos;q()&apos; to quit R.

&gt; flower.data &lt;- read.csv(&quot;/home/yst/Downloads/flowers.csv&quot;)
&gt; names(flower.data)
[1] &quot;Sepal.Length&quot; &quot;Sepal.Width&quot;  &quot;Petal.Length&quot; &quot;Petal.Width&quot;  &quot;Species&quot;     
&gt;</code></pre>
</blockquote>
<h2>Observations</h2>
<p>
	Honestly, I&apos;m not sure what the correct way to find the number of observations recorded is.
	However, there&apos;s a hacky way to find this information that&apos;s incredibly easy to perform.
	Simply display the table.
	A decent programming language indexes from zero.
	R, instead, indexes from one.
	It displays the row number before each row, so just look at the row number of your final row, and you see the number of record - which in this case each represent one observation - you have.
	<bold><code>150</code> observations have been made.</bold>
</p>
<h2>Variables and types</h2>
<p>
	The following variables are present in the table and have the following types:
</p>
<table>
	<tr>
		<th>
			Variable name:
		</th>
		<th>
			Variable type:
		</th>
	</tr>
	<tr>
		<td>
			<code>Sepal.Length</code>
		</td>
		<td>
			numeric
		</td>
	</tr>
	<tr>
		<td>
			<code>Sepal.Width</code>
		</td>
		<td>
			numeric
		</td>
	</tr>
	<tr>
		<td>
			<code>Petal.Length</code>
		</td>
		<td>
			numeric
		</td>
	</tr>
	<tr>
		<td>
			<code>Petal.Width</code>
		</td>
		<td>
			numeric
		</td>
	</tr>
	<tr>
		<td>
			<code>Species</code>
		</td>
		<td>
			factor
		</td>
	</tr>
</table>
<h2>Rounded frequencies</h2>
<p>
	We&apos;re asked to round the sepal lengths, then find the frequency of sepals with a length of seven units.
	R can do the rounding and tallying easily enough, then we can display the table and look at the value associated with <code>7</code>.
</p>
<blockquote>
<pre><code>R version 3.3.3 (2017-03-06) -- &quot;Another Canoe&quot;
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type &apos;license()&apos; or &apos;licence()&apos; for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type &apos;contributors()&apos; for more information and
&apos;citation()&apos; on how to cite R or R packages in publications.

Type &apos;demo()&apos; for some demos, &apos;help()&apos; for on-line help, or
&apos;help.start()&apos; for an HTML browser interface to help.
Type &apos;q()&apos; to quit R.

&gt; flower.data &lt;- read.csv(&quot;/home/yst/Downloads/flowers.csv&quot;)
&gt; x &lt;- round(flower.data\$Sepal.Length, 0)
&gt; table(x)
x
 4  5  6  7  8 
 5 47 68 24  6 
&gt;</code></pre>
</blockquote>
<p>
	<strong>As we can see, there are twenty-four instances.</strong>
</p>
<h2>Unrounded frequencies</h2>
<p>
	We&apos;re asked to take a look at the frequencies of sepal width occurrences without rounding.
	We do this with the following code:
</p>
<blockqoute>
<pre><code>R version 3.3.3 (2017-03-06) -- &quot;Another Canoe&quot;
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type &apos;license()&apos; or &apos;licence()&apos; for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type &apos;contributors()&apos; for more information and
&apos;citation()&apos; on how to cite R or R packages in publications.

Type &apos;demo()&apos; for some demos, &apos;help()&apos; for on-line help, or
&apos;help.start()&apos; for an HTML browser interface to help.
Type &apos;q()&apos; to quit R.

&gt; flower.data &lt;- read.csv(&quot;/home/yst/Downloads/flowers.csv&quot;)
&gt; table(flower.data\$Sepal.Width)

  2 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9   3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9   4 
  1   3   4   3   8   5   9  14  10  26  11  13   6  12   6   4   3   6   2   1 
4.1 4.2 4.4 
  1   1   1 
&gt;</code></pre>
</blockqoute>
<p>
	We&apos;re then asked to look at the first three frequencies and add them up.
	<strong>This gives us a value of eight.</strong>
</p>
<h2>Percentage</h2>
<p>
	The eight we found in the last section tells us that eight of our sampled sepals are <code>2.3</code> units wide or narrower.
	Given that we found there are one hundred fifty samples, this means eight out of one hundred and fifty - a little over 5.3% - are <code>2.3</code> units wide or narrower.
</p>
<h2>Wide sepals</h2>
<p>
	If we add the values of the last three frequencies, we get a value of three, meaning that three of our sampled sepals were 4.1 units wide or wider.
</p>
<h2>Widths of less than four units</h2>
<p>
	The next question asks us how many of the measured sepals had widths less than four.
	For this, we need to be very clear about terminology.
	Many people erroneously include four in this range, but four is not less than itself.
	The question specifically asked for the number of sepals that are <strong>*less than*</strong> four units wide, not <strong>*less than or equal to*</strong>.
</p>
<p>
	To find the correct value, we can either add up all the sepal counts that match this requirement or we can add up the ones that don&apos;t and subtract them from the total.
	<strong>In either case, we see that one hundred forty-six sepals were less than four units in width.</strong>
	The question tells us to round our answer to three decimal places, but as it asked for the count, and not the percentage or ratio, there is nothing to round.
	We simply have a whole number.
</p>
<h2>Graph</h2>
<p>
	We&apos;re asked to graph the table we&apos;ve been working with for the past few sections by calling <code>plot(table(flower.data\$Sepal.Width))</code>, then tell what the tallest bar represents; mean, median, or mode.
	For reference, the command created the following graph:
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/MATH1280/sepal_width_table.png" alt="Sepal width table" class="framed-centred-image" width="677" height="699"/>
<p>
	<strong>As the bars represent the counts that occur for each value, the tallest one is clearly the mode.</strong>
</p>
<h2>Species frequencies</h2>
<p>
	We&apos;re asked to display a frequency table showing the number of each species sampled.
	We can do that like so:
</p>
<blockquote>
<pre><code>R version 3.3.3 (2017-03-06) -- &quot;Another Canoe&quot;
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type &apos;license()&apos; or &apos;licence()&apos; for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type &apos;contributors()&apos; for more information and
&apos;citation()&apos; on how to cite R or R packages in publications.

Type &apos;demo()&apos; for some demos, &apos;help()&apos; for on-line help, or
&apos;help.start()&apos; for an HTML browser interface to help.
Type &apos;q()&apos; to quit R.

&gt; flower.data &lt;- read.csv(&quot;/home/yst/Downloads/flowers.csv&quot;)
&gt; table(flower.data\$Species)

    setosa versicolor  virginica 
        50         50         50 
&gt;</code></pre>
</blockquote>
<p>
	As we can see, each of the three species were sampled an even number of times.
</p>
<h2>Meaning behind the species table</h2>
<p>
	We&apos;re asked two questions about the table above.
	First, why does the first row contain names instead of numbers?
	This should be quite obvious.
	In other tables, numbers were used in the top row, but they weren&apos;t used as numeric values.
	Sure, they were coded as numeric values, but for the purposes of the table, they were used merely as labels for what the numbers in the bottom row represented.
	These labels were numeric because we were looking at the frequency of the occurrence of a numeric field.
	This time, we&apos;re looking at the occurrence frequencies of a a factor field instead, so the first row shows possible factor fields.
	Again though, these aren&apos;t really factors so much as they are labels for the data in the bottom row.
</p>
<p>
	Next, we&apos;re asked what the data in the bottom row represents.
	These numbers are the occurrence rates for each of the values in the top row.
	These numbers will always be positive integers, as things cannot occur a fraction of a time, cannot occur a negative number of times, and are omitted if they occur zero times.
	The reason they&apos;re omitted if they occur zero times is that there are an infinite number of things that occur zero times, and we don&apos;t want to even attempt to iterate over all those possibilities, even if it was somehow possible.
</p>
<div class="APA_references">
	<h2>References:</h2>
	<p>
		Wikipedia. (2018, June 30). Sepal. Retrieved from <a href="https://en.wikipedia.org/wiki/Sepal"><code>https://en.wikipedia.org/wiki/Sepal</code></a>
	</p>
	<p>
		Wikipedia. (2018, June 18). Petal. Retrieved from <a href="https://en.wikipedia.org/wiki/Petal"><code>https://en.wikipedia.org/wiki/Petal</code></a>
	</p>
</div>
END
);
